package com.oumiao.echarts.service;

import com.oumiao.echarts.config.SocketSend;
import com.oumiao.echarts.config.SocketSessionManager;
import lombok.SneakyThrows;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisClientConfig;
import redis.clients.jedis.JedisPubSub;

import javax.annotation.PostConstruct;

@Service
public class RedisConsumerService {

    private Jedis jedis;

    @PostConstruct
    public void init(){
//        this.jedis = new Jedis("192.168.1.189", 6379,100000);
    }

    @EventListener(ApplicationReadyEvent.class)
    public void onApplicationReady(ApplicationReadyEvent event) {
//        JedisPubSub jedisPubSub = new JedisPubSub() {
//            @SneakyThrows
//            @Override
//            public void onMessage(String channel, String message) {
////                System.out.println("channel ->" + channel + " \r\n " + message);
//                SocketSessionManager.sendToAll(message);
//            }
//        };
//        jedis.subscribe(jedisPubSub, "zxdata");
    }


}
